from django.db import models
from django.contrib.auth.models import User
#from infra.meta.models import *

from datetime import datetime




def set_sound_path(instance,filename):
    name =  "upload/audio/%s/%d.wav"%(instance.llang,instance.pk)
    return name
class Sound(models.Model):
    lang = models.CharField(max_length=12,db_index=True)
    term = models.CharField(max_length=300,db_index=True)
    userfile = models.FileField(upload_to=set_sound_path,null=True,blank=True)
    comments = models.CharField(max_length=300,null=True,blank=True)
    #created_by = models.ForeignKey(User,null=True,editable=False)
    def __unicode__(self):
        return self.sound
    class Meta:
        db_table = 'amf_sound'
        #app_label = "exercise"
        #ordering = ['llang_id','term']
    @staticmethod
    def save_sound(lang,model,pk,term,comments=""):
        sound = Sound(lang=lang,
                      term=term,
                      comments=comments)
        sound.save()
        return sound
            
        
